import { createRouter, createWebHistory } from 'vue-router'
import { useCounterStore } from '@/stores/counter'

//创建路由
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'main',
      component:() => import('@/views/MainView.vue'),

    },
    {
      path: '/typescript',
      name: 'typescript',
      component:() => import('@/views/TypescriptView.vue'),
    }
  ],
})
  router.beforeEach((to, from) => {
    if (to.path === '/') {
      return true;
    }else if (useCounterStore().getIsLogin) {
      return true;
    }else{
      return false;
    }
  }
)

export default router
